
from lib.api.SClass import scm
from hytest import STEP, INFO, CHECK_POINT, GSTORE


class Class2:
    name = "添加班级2 - tc000002"

    def teststeps(self):
        STEP(1, "添加班级")

        ret = scm.add_class(gradeid=2, name="八二班", studentlimit=50)
        addRet = ret.json()

        CHECK_POINT("添加结果检查", addRet['retcode'] == 0)

        # 保存添加成功的班级ID
        self.class_id = addRet['id']

        STEP(2, "列出班级")

        ret = scm.list_class(gradeid=2)
        listRet = ret.json()

        INFO(listRet)

        expected = {
            "gradeid": 2,
            "retlist": [
                {
                    "name": "八二班",
                    "grade__name": "八年级",
                    "invitecode": addRet['invitecode'],
                    "studentlimit":50,
                    "studentnumber": 0,
                    "id": addRet['id'],
                    "teacherlist": []
                }
            ],
            "retcode": 0
        }

        CHECK_POINT("列出结果检查", listRet == expected)

    def teardown(self):
        scm.delete_class(classid=self.class_id)


class Class3:
    name = "添加班级3 - tc000003"

    # 测试用例步骤
    def teststeps(self):
        STEP(1, "添加班级")

        res = scm.add_class(gradeid=1, name="七一班", studentlimit=60)
        retAdd = res.json()

        CHECK_POINT("添加结果检查", retAdd['retcode'] == 1)

        STEP(2, "列出班级")

        res = scm.list_class(gradeid=1)
        retList = res.json()

        INFO(retList)

        expected = {
            "gradeid": 1,
            "retlist": [
                {
                    "name": "七一班",
                    "grade__name": "七年级",
                    "invitecode": GSTORE['七一班-invitecode'],
                    "studentlimit": 60,
                    "studentnumber": 0,
                    "id": GSTORE['七一班-id'],
                    "teacherlist": []
                }
            ],
            "retcode": 0
        }

        CHECK_POINT("列出结果检查", retList == expected)


class Class4:
    name = "修改班级1 - tc000051"

    def teststeps(self):
        STEP(1, "修改班级")

        ret = scm.modify_class(classid=GSTORE['七一班-id'],
                               name="七二班", studentlimit=56)
        retAdd = ret.json()

        CHECK_POINT("修改结果检查", retAdd['retcode'] == 0)

        STEP(2, "列出班级")

        ret = scm.list_class(gradeid=1)
        listRet = ret.json()

        INFO(listRet)

        expected = {
            "gradeid": 1,
            "retlist": [
                {
                    "name": "七二班",
                    "grade__name": "七年级",
                    "invitecode": GSTORE['七一班-invitecode'],
                    "studentlimit": 56,
                    "studentnumber": 0,
                    "id": GSTORE['七一班-id'],
                    "teacherlist": []
                }
            ],
            "retcode": 0
        }

        CHECK_POINT("列出结果检查", listRet == expected)


# 修改班级名为一个已经存在的班级名, 修改成功了, 与预期不符
class Class5:
    name = "修改班级2 - tc000052"

    def teststeps(self):
        STEP(1, "修改班级")

        # 已测试: 在初始方法中再创建一个八二班, 改为这个名字也是一样的结果
        ret = scm.modify_class(classid=GSTORE['七一班-id'],
                               name="七一班", studentlimit=56)
        retAdd = ret.json()

        CHECK_POINT("修改结果检查", retAdd['retcode'] == 1)

        STEP(2, "列出班级")

        ret = scm.list_class(gradeid=1)
        listRet = ret.json()

        INFO(listRet)

        expected = {
            "gradeid": 1,
            "retlist": [
                {
                    "name": "七一班",
                    "grade__name": "七年级",
                    "invitecode": GSTORE['七一班-invitecode'],
                    "studentlimit": 60,
                    "studentnumber": 0,
                    "id": GSTORE['七一班-id'],
                    "teacherlist": []
                }
            ],
            "retcode": 0
        }

        CHECK_POINT("列出结果检查", listRet == expected)


class Class8:
    name = "删除班级2 - tc000082"

    def teststeps(self):

        STEP(1, "添加班级")

        ret = scm.add_class(gradeid=2, name="八二班", studentlimit=50)
        addRet = ret.json()

        CHECK_POINT("添加结果检查", addRet['retcode'] == 0)

        # 保存添加成功的班级ID
        self.class_id = addRet['id']

        STEP(2, "删除班级")

        ret = scm.delete_class(classid=self.class_id)
        retDelete = ret.json()

        INFO(retDelete)

        CHECK_POINT("删除结果检查", retDelete['retcode'] == 0)

        STEP(3, "列出班级")

        ret = scm.list_class(gradeid=2)
        retList = ret.json()

        exptcted = {
            "gradeid": 2,
            "retlist": [],
            "retcode": 0
        }

        CHECK_POINT("列出结果检查", retList == exptcted)
